﻿''****************************************************************
'' 这是护理电子病历表单后台运行支持脚本
'' 注意：这是Visual Basic脚本，您可以不区分大小写 
'' 请不要修改系统提供的方法名，以及方法名前面的Overrides关键字
'' Script Language : Visual Basic
'' Author : YangMingkun, Date : 2012-3-18
'' Copyright (C) Heren Health Services (SUPCON) Co.,Ltd.
''****************************************************************

Private VitalNameTable As Hashtable = Nothing
Private XueyaTable As Hashtable = Nothing
Private bFalg As Boolean = False
Private htItemTable As Hashtable = Nothing
'表单脚本初始化
Public Overrides Sub Initialize()
    Me.VitalNameTable = New Hashtable()
    Me.VitalNameTable.Add("体温_口表", "口温")
    Me.VitalNameTable.Add("体温_肛表", "肛温")
    Me.VitalNameTable.Add("体温_腋表", "腋温")
    Me.VitalNameTable.Add("体温_耳表", "耳温")
    Me.VitalNameTable.Add("体温", "腋温")
    Me.VitalNameTable.Add("口温", "体温_口表")
    Me.VitalNameTable.Add("肛温", "体温_肛表")
    Me.VitalNameTable.Add("腋温", "体温")
    Me.VitalNameTable.Add("耳温", "体温_耳表")


    Me.htItemTable = New Hashtable()
    Me.htItemTable.Add("2:00:00", 1)
    Me.htItemTable.Add("6:00:00", 1)
    Me.htItemTable.Add("10:00:00", 1)
    Me.htItemTable.Add("14:00:00", 1)
    Me.htItemTable.Add("18:00:00", 1)
    Me.htItemTable.Add("22:00:00", 1)
    'Me.ShowMessage("表单已完成加载!")
    '在此函数中来查询和设置表单中的相关数据
    '可以调用GetSystemContext函数获取系统中已有数据，也可以从数据库中读取其他任意数据

End Sub


'获取关键数据列表
Public Overrides Function GetKeyDataList() As List(Of KeyData)
    Dim CheckChuRuLiangNameResult1 As String = Me.CheckChuRuLiangName(CType(Me.FindControl("XDataGrid2"), XDataGrid))
    '    showmessage(CheckChuRuLiangNameResult1)
    If CheckChuRuLiangNameResult1.Contains("小结") OrElse CheckChuRuLiangNameResult1.Contains("总结") Then
        ShowMessage("入量表格中请录入入量明细，请不要包含小结，小结可在护理记录单列表单独插入自动计算！")
        Exit Function
    ElseIf CheckChuRuLiangNameResult1 <> "" Then
        ShowMessage("入量表格中包含相同入量名称，请更改！")
        Exit Function
    End If
    Dim CheckChuRuLiangNameResult2 As String = Me.CheckChuRuLiangName(CType(Me.FindControl("XDataGrid1"), XDataGrid))
    '    showmessage(CheckChuRuLiangNameResult2)
    If CheckChuRuLiangNameResult2.Contains("小结") OrElse CheckChuRuLiangNameResult2.Contains("总结") Then
        ShowMessage("出量表格中请录入出量明细，请不要包含小结，小结可在护理记录单列表单独插入自动计算！")
        Exit Function
    ElseIf CheckChuRuLiangNameResult2 <> "" Then
        ShowMessage("出量表格中包含相同入量名称，请更改！")
        Exit Function
    End If
    Dim keyDataList As New List(Of KeyData)
    keyDataList.Add(New KeyData("意识", Me.GetControlText("XComboBox1"), "字符", ""))
    keyDataList.Add(New KeyData("心律", Me.GetControlText("XTextBox10"), "字符", ""))
    keyDataList.Add(New KeyData("心电监护", Me.GetControlText("XComboBox6"), "字符", ""))
    keyDataList.Add(New KeyData("氧饱和度", Me.GetControlText("XTextBox6"), "数值", "%"))
    keyDataList.Add(New KeyData("血糖", Me.GetControlText("XTextBox1"), "数值", "%"))
    keyDataList.Add(New KeyData("手术敷料", Me.GetControlText("XTextBox2"), "数值", "%"))
    Dim pifuState As New StringBuilder
    If Me.IsCheckButtonChecked("XCheckBox1") Then
        pifuState.Append("完整")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox7") Then
        pifuState.Append("破损")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox4") Then
        pifuState.Append("皮疹")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox3") Then
        pifuState.Append("瘀斑")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox10") Then
        pifuState.Append("红疹")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox6") Then
        pifuState.Append("出血点")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox2") Then
        pifuState.Append("溃疡")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox5") Then
        pifuState.Append("压疮")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox8") Then
        pifuState.Append("水肿")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox9") Then
        pifuState.Append("浸渍")
        pifuState.AppendLine()
    End If
    If Me.IsCheckButtonChecked("XCheckBox11") Then
        pifuState.Append("其他")
        '        pifuState.AppendLine()
    End If
    keyDataList.Add(New KeyData("皮肤", pifuState.toString(), "字符", ""))

    Dim recorddate As DateTime
    Me.GetSystemContext("评估时间", recorddate)

    If Me.htItemTable(recorddate.toString("H:mm:ss")) = 1 Then
        '        If Me.GetControlText("XComboBox2").Trim() <> ""  Then
        '	        Dim TiWendata1 As New KeyData(Me.GetControlText("XComboBox2"), Me.GetControlText("XTextBox3"), "数值", "℃", 1, recorddate)
        '			TiWendata1.Category = 1
        '			keyDataList.Add(TiWendata1)        
        '	    End If
        '	    
        '	'    keyDataList.Add(New KeyData("体温", Me.GetControlText("XTextBox3"), "数值", "℃"))
        '	    keyDataList.Add(New KeyData(Me.VitalNameTable(Me.GetControlText("XComboBox2")), Me.GetControlText("XTextBox3"), "数值", "℃", 1, recorddate)）
        '	    
        '	    If Me.VitalNameTable(Me.GetControlText("XComboBox2")) <> "体温" Then
        '	          keyDataList.Add(New KeyData("体温", Me.GetControlText("XTextBox3"), "数值", "℃"))  
        '	    End If   

        If Me.GetControlText("XComboBox2") = "" Then
            keyDataList.Add(New KeyData(Me.VitalNameTable("腋温"), Me.GetControlText("XTextBox3"), "数值", "℃", 1, recorddate))
        ElseIf Me.GetControlText("XComboBox2") <> "" Then
            keyDataList.Add(New KeyData(Me.VitalNameTable(Me.GetControlText("XComboBox2")), Me.GetControlText("XTextBox3"), "数值", "℃", 1, recorddate))
        End If


        If Me.VitalNameTable(Me.GetControlText("XComboBox2")) <> "体温" Then
            keyDataList.Add(New KeyData("体温", Me.GetControlText("XTextBox3"), "数值", "℃"))
        End If

        keyDataList.Add(New KeyData("脉搏", Me.GetControlText("XTextBox4"), "数值", "次/分", 1, recorddate))
        keyDataList.Add(New KeyData("心率", Me.GetControlText("XTextBox5"), "数值", "次/分", 1, recorddate))
        keyDataList.Add(New KeyData("呼吸", Me.GetControlText("XTextBox7"), "数值", "次/分", 1, recorddate))
    Else
        '        If Me.GetControlText("XComboBox2").Trim() <> ""  Then
        '	        Dim TiWendata1 As New KeyData(Me.GetControlText("XComboBox2"), Me.GetControlText("XTextBox3"), "数值", "℃", 3, recorddate)
        '			TiWendata1.Category = 1
        '			keyDataList.Add(TiWendata1)        
        '	    End If
        '	    
        '	'    keyDataList.Add(New KeyData("体温", Me.GetControlText("XTextBox3"), "数值", "℃"))
        '	    keyDataList.Add(New KeyData(Me.VitalNameTable(Me.GetControlText("XComboBox2")), Me.GetControlText("XTextBox3"), "数值", "℃", 3, recorddate))
        '	    
        '	    If Me.VitalNameTable(Me.GetControlText("XComboBox2")) <> "体温" Then
        '	          keyDataList.Add(New KeyData("体温", Me.GetControlText("XTextBox3"), "数值", "℃" , 3, recorddate))  
        '	    End If    
        If Me.GetControlText("XComboBox2") = "" Then
            keyDataList.Add(New KeyData(Me.VitalNameTable("腋温"), Me.GetControlText("XTextBox3"), "数值", "℃", 3, recorddate))
        ElseIf Me.GetControlText("XComboBox2") <> "" Then
            keyDataList.Add(New KeyData(Me.VitalNameTable(Me.GetControlText("XComboBox2")), Me.GetControlText("XTextBox3"), "数值", "℃", 3, recorddate))
        End If


        If Me.VitalNameTable(Me.GetControlText("XComboBox2")) <> "体温" Then
            keyDataList.Add(New KeyData("体温", Me.GetControlText("XTextBox3"), "数值", "℃"))
        End If

        keyDataList.Add(New KeyData("脉搏", Me.GetControlText("XTextBox4"), "数值", "次/分", 3, recorddate))
        keyDataList.Add(New KeyData("心率", Me.GetControlText("XTextBox5"), "数值", "次/分", 3, recorddate))
        keyDataList.Add(New KeyData("呼吸", Me.GetControlText("XTextBox7"), "数值", "次/分", 3, recorddate))
    End If


    '    Dim dtFlag As DateTime = New DateTime(recorddate.Year, recorddate.Month, recorddate.Day, 12,0,0).ToString("yyyy-MM-dd HH:mm:ss")
    '    If recorddate < dtFlag Then
    '         keyDataList.Add(New KeyData("血压high", Me.GetControlText("XTextBox8"), "数值", "mmHg", 1,recorddate.Date))
    '         keyDataList.Add(New KeyData("血压Low", Me.GetControlText("XTextBox9"), "数值", "mmHg", 1,recorddate.Date))      
    '    Else If recorddate > dtFlag Then
    '         keyDataList.Add(New KeyData("血压high2", Me.GetControlText("XTextBox8"), "数值", "mmHg", 1,recorddate.Date))
    '         keyDataList.Add(New KeyData("血压Low2", Me.GetControlText("XTextBox9"), "数值", "mmHg", 1,recorddate.Date))           
    '    End If
    '    keyDataList.Add(New KeyData("血压high", Me.GetControlText("XTextBox8"), "数值", "mmHg", 1,recorddate))
    '    keyDataList.Add(New KeyData("血压Low", Me.GetControlText("XTextBox9"), "数值", "mmHg", 1,recorddate))
    Dim xueyaFlag As String = Me.GetControlText("XComboBox3").trim()

    If xueyaFlag <> "" AndAlso xueyaFlag <> "未测" Then
        If Me.GetControlText("XTextBox8").trim() = "" Or Me.GetControlText("XTextBox9").trim() = "" Then
            ShowMessage("血压值为空，请填写血压后，再保存！")
            Exit Function
        End If
    End If

    If xueyaFlag <> "" AndAlso xueyaFlag = "早血压" Then
        keyDataList.Add(New KeyData("血压high", Me.GetControlText("XTextBox8"), "字符", "mmHg", 1, recorddate.Date))
        keyDataList.Add(New KeyData("血压Low", Me.GetControlText("XTextBox9"), "字符", "mmHg", 1, recorddate.Date))
    ElseIf xueyaFlag <> "" AndAlso xueyaFlag = "晚血压" Then
        keyDataList.Add(New KeyData("血压high2", Me.GetControlText("XTextBox8"), "字符", "mmHg", 1, recorddate.Date))
        keyDataList.Add(New KeyData("血压Low2", Me.GetControlText("XTextBox9"), "字符", "mmHg", 1, recorddate.Date))
    ElseIf xueyaFlag <> "" AndAlso xueyaFlag = "血压3" Then
        keyDataList.Add(New KeyData("血压high3", Me.GetControlText("XTextBox8"), "字符", "mmHg", 1, recorddate.Date))
        keyDataList.Add(New KeyData("血压Low3", Me.GetControlText("XTextBox9"), "字符", "mmHg", 1, recorddate.Date))
    ElseIf xueyaFlag <> "" AndAlso xueyaFlag = "血压4" Then
        keyDataList.Add(New KeyData("血压high4", Me.GetControlText("XTextBox8"), "字符", "mmHg", 1, recorddate.Date))
        keyDataList.Add(New KeyData("血压Low4", Me.GetControlText("XTextBox9"), "字符", "mmHg", 1, recorddate.Date))
    ElseIf xueyaFlag <> "" AndAlso xueyaFlag = "血压5" Then
        keyDataList.Add(New KeyData("血压high5", Me.GetControlText("XTextBox8"), "字符", "mmHg", 1, recorddate.Date))
        keyDataList.Add(New KeyData("血压Low5", Me.GetControlText("XTextBox9"), "字符", "mmHg", 1, recorddate.Date))
    ElseIf xueyaFlag <> "" AndAlso xueyaFlag = "血压6" Then
        keyDataList.Add(New KeyData("血压high6", Me.GetControlText("XTextBox8"), "字符", "mmHg", 1, recorddate.Date))
        keyDataList.Add(New KeyData("血压Low6", Me.GetControlText("XTextBox9"), "字符", "mmHg", 1, recorddate.Date))
    End If


    Dim column1_value As New StringBuilder
    Dim column2_value As New StringBuilder
    Dim column3_value As New StringBuilder
    Dim column4_value As New StringBuilder

    Dim datagrid As XDataGrid = Me.FindControl("XDataGrid2")
    For index As Integer = 0 To datagrid.Rows.Count - 1
        Dim cell1Value As String = datagrid.GetCellValue(index, 0, "")
        Dim cell2Value As String = String.Empty
        Dim cell3Value As String = String.Empty
        Dim cell4Value As String = String.Empty

        If cell1Value.Trim() = "" Then
            Continue For
        End If
        cell2Value = datagrid.GetCellValue(index, 1, 0)
        cell3Value = datagrid.GetCellValue(index, 2, 0)
        cell4Value = datagrid.GetCellValue(index, 3, "")
        If cell3Value.toString().Trim() <> "" Then
            column1_value.Append(cell1Value)
            If index < datagrid.Rows.Count - 1 Then column1_value.AppendLine()
            column2_value.Append(cell2Value)
            If index < datagrid.Rows.Count - 1 Then column2_value.AppendLine()
            column3_value.Append(cell3Value)
            If index < datagrid.Rows.Count - 1 Then column3_value.AppendLine()
            column4_value.Append(cell4Value)
            If index < datagrid.Rows.Count - 1 Then column4_value.AppendLine()
            dataGrid.SetRowState(index, 0)
        End If
        keyDataList.Add(New KeyData(cell1Value, cell3Value.Trim(), "数值", "ml", 3, recorddate, "入量"))
    Next
    keyDataList.Add(New KeyData("入量名称", column1_value.ToString(), "字符", ""))
    keyDataList.Add(New KeyData("入量(备用量)", column2_value.ToString(), "数值", "ml"))
    keyDataList.Add(New KeyData("入量", column3_value.ToString(), "数值", "ml"))
    keyDataList.Add(New KeyData("途经", column4_value.ToString(), "字符", "ml"))

    column1_value.Remove(0, column1_value.Length)
    column2_value.Remove(0, column2_value.Length)
    datagrid = Me.FindControl("XDataGrid1")
    For index As Integer = 0 To datagrid.Rows.Count - 1
        Dim cellValue As String = datagrid.GetCellValue(index, 0, "")
        Dim cell2Value As String = String.Empty
        If cellValue.Trim() = "" Then
            Continue For
        End If
        cell2Value = datagrid.GetCellValue(index, 1, 0)
        If cell2Value.toString().Trim() <> "" Then
            column1_value.Append(cellValue)
            If index < datagrid.Rows.Count - 1 Then column1_value.AppendLine()
            column2_value.Append(cell2Value)
            If index < datagrid.Rows.Count - 1 Then column2_value.AppendLine()
            dataGrid.SetRowState(index, 0)
        End If
        keyDataList.Add(New KeyData(cellValue, cell2Value.Trim(), "数值", "ml", 3, recorddate, "出量"))
    Next
    keyDataList.Add(New KeyData("出量名称", column1_value.ToString(), "字符", ""))
    keyDataList.Add(New KeyData("出量", column2_value.ToString(), "数值", "ml"))

    Return keyDataList
End Function

''同步体征数据
Public Sub SyncPhysicalData(ByVal recorddate As DateTime)
    Me.bFalg = False
    Dim value As Object
    Me.GetSystemContext("病人ID号", value)
    Dim szPatientID As String = value

    Me.GetSystemContext("入院次", value)
    Dim szVisitID As String = value

    Dim sql As New StringBuilder
    sql.Append("select recording_date, time_point, vital_signs, vital_signs_values ")
    sql.Append("from vital_signs_rec@link_emr ")
    sql.AppendFormat("where patient_id='{0}' and visit_id='{1}'", szPatientID, szVisitID)
    sql.AppendFormat(" and time_point=to_date('{0}', 'yyyy-mm-dd hh24:mi:ss')", New DateTime(recorddate.Year, recorddate.Month, recorddate.Day, recorddate.Hour, recorddate.Minute, 0).ToString("yyyy-MM-dd HH:mm:ss"))

    Dim dataTemp As New DataSet
    Me.ExecuteQuery(sql.ToString(), dataTemp)
    If dataTemp Is Nothing OrElse dataTemp.Tables.Count <= 0 Then
        Exit Sub
    End If

    '    If dataTemp.Tables(0).Rows.Count > 0 Then
    '		    Me.SetControlText("XTextBox3", "")
    '		    Me.SetControlText("XTextBox4",  "")
    '		    Me.SetControlText("XTextBox5",  "")
    '		    Me.SetControlText("XTextBox7",  "") 
    '    End If

    For Each row As DataRow In dataTemp.Tables(0).Rows
        Dim strTemp As String = Nothing
        If row.IsNull(3) OrElse row(3).toString() = "" Then
            Continue For
        End If
        strTemp = Double.Parse(Row(3))
        If row(2) IsNot DBNULL.Value AndAlso (row(2) = "体温" OrElse row(2) = "体温_肛表" _
          OrElse row(2) = "体温_耳表" OrElse row(2) = "体温_口表") Then
            Me.SetControlText("XComboBox2", Me.VitalNameTable(row(2)))
            If strTemp <> Me.GetControlText("XTextBox3").Trim() Then
                Me.bFalg = True
                Me.SetControlText("XTextBox3", strTemp)
            End If
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).Contains("脉搏") Then
            If strTemp <> Me.GetControlText("XTextBox4").Trim() Then
                Me.bFalg = True
                Me.SetControlText("XTextBox4", strTemp)
            End If
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).Contains("心率") Then
            If strTemp <> Me.GetControlText("XTextBox5").Trim() Then
                Me.bFalg = True
                Me.SetControlText("XTextBox5", strTemp)
            End If
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).Contains("呼吸") Then
            If strTemp <> Me.GetControlText("XTextBox7").Trim() Then
                Me.bFalg = True
                Me.SetControlText("XTextBox7", strTemp)
            End If
            '        Else If row(2) IsNot DBNULL.Value AndAlso row(2).Contains("血压high")  Then
            '              Me.SetControlText("XTextBox8", row(3)) 
            '        Else If row(2) IsNot DBNULL.Value AndAlso row(2).Contains("血压Low")  Then
            '              Me.SetControlText("XTextBox9", row(3))                 
        End If
    Next

    sql.Remove(0, sql.Length)
    sql.Append("select recording_date, time_point, vital_signs, vital_signs_values ")
    sql.Append("from vital_signs_rec@link_emr ")
    sql.AppendFormat("where patient_id='{0}' and visit_id='{1}'", szPatientID, szVisitID)
    sql.AppendFormat(" and recording_date=to_date('{0}', 'yyyy-mm-dd hh24:mi:ss')", recorddate.Date)
    '    showMessage(sql.toString())
    dataTemp = Nothing
    Me.ExecuteQuery(sql.ToString(), dataTemp)
    If dataTemp Is Nothing OrElse dataTemp.Tables.Count <= 0 Then
        Exit Sub
    End If

    '    If dataTemp.Tables(0).Rows.Count > 0 Then
    '		    Me.SetControlText("XTextBox8",  "") 
    '		    Me.SetControlText("XTextBox9",  "")
    '    End If
    '    
    '    Dim dtFlag As DateTime = New DateTime(recorddate.Year, recorddate.Month, recorddate.Day, 12,0,0).ToString("yyyy-MM-dd HH:mm:ss")
    '    
    '    For Each row As DataRow In dataTemp.Tables(0).Rows
    '        Dim strTemp As String = Nothing
    '        If row.IsNull(3) OrElse row(3).toString() = "" Then
    '            Continue For
    '        End If
    '        strTemp = Double.Parse(Row(3))       
    '          If row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high" AndAlso  recorddate < dtFlag Then
    '             If strTemp <>  Me.GetControlText("XTextBox8").Trim() Then
    '                  Me.bFalg = true
    '                  Me.SetControlText("XTextBox8", strTemp)
    '             End If     
    '          Else If row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low" AndAlso  recorddate < dtFlag Then
    '             If strTemp <>  Me.GetControlText("XTextBox9").Trim()  Then
    '                  Me.bFalg = true
    '                  Me.SetControlText("XTextBox9", strTemp)
    '             End If     
    '          Else If row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high2" AndAlso  recorddate > dtFlag Then
    '              If strTemp <>  Me.GetControlText("XTextBox8").Trim()  Then
    '                  Me.bFalg = true
    '                  Me.SetControlText("XTextBox8", strTemp)
    '              End If    
    '          Else If row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low2" AndAlso  recorddate > dtFlag Then  
    '              If strTemp <>  Me.GetControlText("XTextBox9").Trim() Then
    '                   Me.bFalg = true
    '                   Me.SetControlText("XTextBox9", strTemp)
    '              End If     
    '          End If
    '    Next    
    Me.XueyaTable = New Hashtable()
    Dim dtFlag As DateTime = New DateTime(recorddate.Year, recorddate.Month, recorddate.Day, 12, 0, 0).ToString("yyyy-MM-dd HH:mm:ss")
    '    showMessage(recorddate.toString() + "    " +  dtFlag.toString())
    For Each row As DataRow In dataTemp.Tables(0).Rows
        Dim strTemp As String = Nothing
        If row.IsNull(3) OrElse row(3).toString() = "" Then
            Continue For
        End If
        strTemp = Double.Parse(Row(3))
        If row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high" Then
            '              If strTemp <>  Me.GetControlText("XTextBox8").Trim() Then     
            '                   bFalg = true
            '                   Me.SetControlText("XComboBox1", "血压1")
            '                   Me.SetControlText("XTextBox8", strTemp)
            If Me.XueyaTable.Contains("血压high") Then
                Me.XueyaTable("血压high") = strTemp
            Else
                Me.XueyaTable.Add("血压high", strTemp)
            End If
            '              End If       
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low" Then
            '              If strTemp <>  Me.GetControlText("XTextBox4").Trim()  Then
            '                   bFalg = true
            '                   Me.SetControlText("XComboBox1", "血压1")
            '                   Me.SetControlText("XTextBox4", strTemp)  
            If Me.XueyaTable.Contains("血压Low") Then
                Me.XueyaTable("血压Low") = strTemp
            Else
                Me.XueyaTable.Add("血压Low", strTemp)
            End If
            '              End If            

        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high2" Then
            '              If strTemp <>  Me.GetControlText("XTextBox8").Trim()  Then
            '                   bFalg = true
            '                   Me.SetControlText("XComboBox1", "血压2")
            '                   Me.SetControlText("XTextBox8",strTemp) 
            If Me.XueyaTable.Contains("血压high2") Then
                Me.XueyaTable("血压high2") = strTemp
            Else
                Me.XueyaTable.Add("血压high2", strTemp)
            End If
            '              End If   
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low2" Then
            '              If strTemp <>  Me.GetControlText("XTextBox4").Trim()  Then
            '                   bFalg = true
            '                   Me.SetControlText("XComboBox1", "血压2")
            '                   Me.SetControlText("XTextBox4", strTemp)  
            If Me.XueyaTable.Contains("血压Low2") Then
                Me.XueyaTable("血压Low2") = strTemp
            Else
                Me.XueyaTable.Add("血压Low2", strTemp)
            End If
            '              End If 
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low3" Then
            '              If strTemp <>  Me.GetControlText("XTextBox4").Trim()  Then
            '                   bFalg = true
            If Me.XueyaTable.Contains("血压Low3") Then
                Me.XueyaTable("血压Low3") = strTemp
            Else
                Me.XueyaTable.Add("血压Low3", strTemp)
            End If
            '              End If       
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high3" Then
            '              If strTemp <>  Me.GetControlText("XTextBox4").Trim()  Then
            '                   bFalg = true
            If Me.XueyaTable.Contains("血压high3") Then
                Me.XueyaTable("血压high3") = strTemp
            Else
                Me.XueyaTable.Add("血压high3", strTemp)
            End If
            '              End If   
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high4" Then
            If Me.XueyaTable.Contains("血压high4") Then
                Me.XueyaTable("血压high4") = strTemp
            Else
                Me.XueyaTable.Add("血压high4", strTemp)
            End If
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low4" Then
            '              If strTemp <>  Me.GetControlText("XTextBox4").Trim()  Then
            '                   bFalg = true
            If Me.XueyaTable.Contains("血压Low4") Then
                Me.XueyaTable("血压Low4") = strTemp
            Else
                Me.XueyaTable.Add("血压Low4", strTemp)
            End If
            '              End If  
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high5" Then
            If Me.XueyaTable.Contains("血压high5") Then
                Me.XueyaTable("血压high5") = strTemp
            Else
                Me.XueyaTable.Add("血压high5", strTemp)
            End If
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low5" Then
            If Me.XueyaTable.Contains("血压Low5") Then
                Me.XueyaTable("血压Low5") = strTemp
            Else
                Me.XueyaTable.Add("血压Low5", strTemp)
            End If
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压high6" Then
            '              If strTemp <>  Me.GetControlText("XTextBox4").Trim()  Then
            '                   bFalg = true
            If Me.XueyaTable.Contains("血压high6") Then
                Me.XueyaTable("血压high6") = strTemp
            Else
                Me.XueyaTable.Add("血压high6", strTemp)
            End If
            '              End If  
        ElseIf row(2) IsNot DBNULL.Value AndAlso row(2).toString() = "血压Low6" Then
            '              If strTemp <>  Me.GetControlText("XTextBox4").Trim()  Then
            '                   bFalg = true
            If Me.XueyaTable.Contains("血压Low6") Then
                Me.XueyaTable("血压Low6") = strTemp
            Else
                Me.XueyaTable.Add("血压Low6", strTemp)
            End If
            '              End If  
        End If
    Next

End Sub


'更新表单中指定的数据
Public Overrides Function UpdateFormData(ByVal param As String, ByVal data As Object) As Boolean
    If param = "更新控件状态" Then
        Me.SetControlEnabled(Me.FindControl("RootControl1"), Me.ToBoolValue(data, False))
        Return bFalg
    ElseIf param = "数据同步" Then
        Dim recorddate As DateTime
        Me.GetSystemContext("评估时间", recorddate)
        Me.SyncPhysicalData(recorddate)
        Return Me.bFalg
    End If
    Return True
End Function

'当单元格收到输入焦点，从而成为 DataGridView 中的当前单元格时发生。
Private Sub XDataGrid2_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
    'e.ColumnIndex, System.Int32
    'e.RowIndex, System.Int32
    Dim datagrid As XDataGrid = CType(sender, XDataGrid)
    Dim cellValue1 As String = datagrid.GetCellValue(e.RowIndex, 0, "")
    Dim cellValue2 As String = datagrid.GetCellValue(e.RowIndex, 1, "")
    Dim cellValue3 As String = datagrid.GetCellValue(e.RowIndex, 2, "")
    Dim cellValue4 As String = datagrid.GetCellValue(e.RowIndex, 3, "")
    '    If e.RowIndex = 0  AndAlso cellValue1 <> "" AndAlso datagrid.CurrentRow.State.toString() = "Normal" Then
    '         datagrid.CurrentRow.Cells(0).ReadOnly = True
    '    Else If e.RowIndex <> 0  AndAlso cellValue1 <> "" AndAlso datagrid.CurrentRow.State.toString() = "Normal" Then
    '         datagrid.CurrentRow.Cells(0).ReadOnly = True     
    '    Else If e.RowIndex <> 0  AndAlso cellValue2 <> "" AndAlso datagrid.CurrentRow.State.toString() = "Normal" Then        
    '         datagrid.CurrentRow.Cells(0).ReadOnly = True   
    '    Else If e.RowIndex <> 0  AndAlso cellValue3 <> "" AndAlso datagrid.CurrentRow.State.toString() = "Normal" Then
    '         datagrid.CurrentRow.Cells(0).ReadOnly = True   
    '    End If
End Sub

'当单元格收到输入焦点，从而成为 DataGridView 中的当前单元格时发生。
Private Sub XDataGrid1_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
    'e.ColumnIndex, System.Int32
    'e.RowIndex, System.Int32
    Dim datagrid As XDataGrid = CType(sender, XDataGrid)
    Dim cellValue1 As String = datagrid.GetCellValue(e.RowIndex, 0, "")
    Dim cellValue2 As String = datagrid.GetCellValue(e.RowIndex, 1, "")
    '    If e.RowIndex = 0  AndAlso cellValue1 <> "" AndAlso datagrid.CurrentRow.State.toString() = "Normal" Then
    '         datagrid.CurrentRow.Cells(0).ReadOnly = True
    '    Else If e.RowIndex <> 0  AndAlso cellValue1 <> "" AndAlso datagrid.CurrentRow.State.toString() = "Normal" Then
    '         datagrid.CurrentRow.Cells(0).ReadOnly = True     
    '    End If
End Sub

'入量验证
Private Sub XDataGrid2_NumericValidating(ByVal sender As System.Object, ByVal e As Heren.Common.Controls.TableView.NumericValidatingEventArgs)
    'e.RowIndex, System.Int32
    'e.ColumnIndex, System.Int32
    'e.Value, System.Object
    'e.IsNumeric, System.Boolean
    'e.IsInteger, System.Boolean
    If e.ColumnIndex = 1 Then
        e.IsNumeric = True
    ElseIf e.ColumnIndex = 2 Then
        e.IsNumeric = True
    End If
End Sub

'获取表单中指定的数据
Public Overrides Function GetFormData(ByVal param As Object) As Object
    If param = "表单摘要" Then
        Return Me.GetFormSummary()
    End If
    Return Nothing
End Function

'出量验证
Private Sub XDataGrid1_NumericValidating(ByVal sender As System.Object, ByVal e As Heren.Common.Controls.TableView.NumericValidatingEventArgs)
    'e.RowIndex, System.Int32
    'e.ColumnIndex, System.Int32
    'e.Value, System.Object
    'e.IsNumeric, System.Boolean
    'e.IsInteger, System.Boolean
    If e.ColumnIndex = 1 Then
        e.IsNumeric = True
    End If
End Sub

'入量自动新增改变行头图标
Private Sub XDataGrid2_RowsAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs)
    'e.RowIndex, System.Int32
    'e.RowCount, System.Int32
    CType(sender, XDataGrid).SetRowState(e.RowIndex, 1)
End Sub

'出量自动新增改变行头图标
Private Sub XDataGrid1_RowsAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs)
    'e.RowIndex, System.Int32
    'e.RowCount, System.Int32
    CType(sender, XDataGrid).SetRowState(e.RowIndex, 1)
End Sub

'删除入量
Private Sub XButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim patient_id As String = ""
    Me.GetSystemContext("病人ID号", patient_id)
    Dim visit_id As String = ""
    Me.GetSystemContext("入院次", visit_id)
    Dim recorddate As DateTime
    Me.GetSystemContext("评估时间", recorddate)
    Dim dataGrid As XDataGrid = CType(Me.FindControl("XDataGrid2"), XDataGrid)
    Dim cellValue1 As String = ""
    If dataGrid.CurrentRow IsNot Nothing Then
        cellValue1 = dataGrid.CurrentRow.Cells(0).Value
    End If

    If cellValue1 Is Nothing OrElse cellValue1 = "" Then
        If dataGrid.CurrentCell IsNot Nothing AndAlso dataGrid.CurrentCell.RowIndex <> dataGrid.Rows.Count - 1 Then
            If dataGrid.CurrentRow IsNot Nothing Then
                dataGrid.Rows.Remove(dataGrid.CurrentRow)
            End If
        End If
        Exit Sub
    End If
    Dim sql As String = Me.GetSaveSQL(patient_id, visit_id, "0", recorddate, recorddate _
              , cellValue1, "", "数值", "ML", 1, 1, "入量", "", "")
    If Not Me.ExecuteUpdate(True, sql) Then
        Me.ShowError("入量删除失败！")
        Exit Sub
    End If
    If dataGrid.CurrentCell IsNot Nothing AndAlso dataGrid.CurrentCell.RowIndex <> dataGrid.Rows.Count - 1 Then
        If dataGrid.CurrentRow IsNot Nothing Then
            dataGrid.Rows.Remove(dataGrid.CurrentRow)
        End If
    End If
    Exit Sub

End Sub

'删除出量
Private Sub XButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim patient_id As String = ""
    Me.GetSystemContext("病人ID号", patient_id)
    Dim visit_id As String = ""
    Me.GetSystemContext("入院次", visit_id)
    Dim recorddate As DateTime
    Me.GetSystemContext("评估时间", recorddate)
    Dim dataGrid As XDataGrid = CType(Me.FindControl("XDataGrid1"), XDataGrid)
    Dim cellValue1 As String = ""
    If dataGrid.CurrentRow IsNot Nothing Then
        cellValue1 = dataGrid.CurrentRow.Cells(0).Value
    End If

    If cellValue1 Is Nothing OrElse cellValue1 = "" Then
        If dataGrid.CurrentCell IsNot Nothing AndAlso dataGrid.CurrentCell.RowIndex <> dataGrid.Rows.Count - 1 Then
            If dataGrid.CurrentRow IsNot Nothing Then
                dataGrid.Rows.Remove(dataGrid.CurrentRow)
            End If
        End If
        Exit Sub
    End If
    Dim sql As String = Me.GetSaveSQL(patient_id, visit_id, "0", recorddate, recorddate _
              , cellValue1, "", "数值", "ML", 1, 1, "入量", "", "")
    If Not Me.ExecuteUpdate(True, sql) Then
        Me.ShowError("出量删除失败！")
        Exit Sub
    End If
    If dataGrid.CurrentCell IsNot Nothing AndAlso dataGrid.CurrentCell.RowIndex <> dataGrid.Rows.Count - 1 Then
        If dataGrid.CurrentRow IsNot Nothing Then
            dataGrid.Rows.Remove(dataGrid.CurrentRow)
        End If
    End If
    Exit Sub
End Sub

'新增入量
Private Sub XButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim dataGrid As XDataGrid = CType(Me.FindControl("XDataGrid2"), XDataGrid)
    Dim rowIndex As Integer = dataGrid.Rows.Add()
    dataGrid.SetRowState(rowIndex, 1)
End Sub

'新增出量
Private Sub XButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim dataGrid As XDataGrid = CType(Me.FindControl("XDataGrid1"), XDataGrid)
    Dim rowIndex As Integer = dataGrid.Rows.Add()
    dataGrid.SetRowState(rowIndex, 1)
End Sub

'组织指定的体征数据保存时的SQL
Private Function GetSaveSQL(ByVal patientId As String, _
                            ByVal visitId As String, _
                            ByVal subId As String, _
                            ByVal recordDate As DateTime, _
                            ByVal recordTime As DateTime, _
                            ByVal recordName As String, _
                            ByVal recordData As String, _
                            ByVal dataType As String, _
                            ByVal dataUnit As String, _
                            ByVal category As Integer, _
                            ByVal containsTime As Integer, _
                            ByVal remarks As String, _
                            ByVal sourceTag As String, _
                            ByVal sourceType As String) As String

    Return String.Format("SaveVitalSignsData('{0}', '{1}', '{2}', {3}, {4}, '{5}', '{6}', '{7}', '{8}', {9}, {10}, '{11}','{12}','{13}')" _
                , patientId, visitId, subId _
                , String.Format("to_date('{0}', 'yyyy-mm-dd hh24:mi:ss')", recordDate.Date.ToString("yyyy-MM-dd")) _
                , String.Format("to_date('{0}', 'yyyy-mm-dd hh24:mi:ss')", recordTime.ToString("yyyy-MM-dd HH:mm:ss")) _
                , recordName, recordData, dataType, dataUnit, category, containsTime, remarks, sourceTag, sourceType)
End Function

'单击组件时发生。
Private Sub XButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim result As DataTable = Nothing
    Me.raisecustomevent(sender, "导入医嘱记录", Nothing, Nothing, result)
    If result Is Nothing OrElse result.Rows.Count <= 0 Then
        Exit Sub
    End If
    Dim XGrid As XDataGrid = CType(Me.FindControl("XDataGrid2"), XDataGrid)
    For index As Integer = 0 To result.Rows.Count - 1
        Dim gridIndex As Integer = XGrid.Rows.Add()
        Dim gridRow As DataGridViewRow = XGrid.Rows(gridIndex)
        gridRow.Cells(0).Value = Me.GetFieldValue(result, index, "医嘱内容")
        gridRow.Cells(1).Value = Me.GetFieldValue(result, index, "剂量")
        gridRow.Cells(3).Value = Me.GetFieldValue(result, index, "途径")
    Next index
End Sub

Public Function CheckChuRuLiangName(ByVal dataGrid As XDataGrid) As String
    Dim result As New StringBuilder
    For index As Integer = 0 To datagrid.Rows.Count - 1
        Dim cell1Value As String = datagrid.GetCellValue(index, 0, "")
        If cell1Value = "" Then
            Continue For
        End If
        If cell1Value.Contains("小结") OrElse cell1Value.Contains("总结") Then
            result.Remove(0, result.length)
            result.Append(cell1Value)
            Return result.toString()
        End If
        For nextIndex As Integer = index + 1 To datagrid.Rows.Count - 1
            Dim cell2Value As String = datagrid.GetCellValue(nextIndex, 0, "")
            If cell2Value.Contains("小结") OrElse cell2Value.Contains("总结") Then
                result.Remove(0, result.length)
                result.Append(cell2Value)
                Return result.toString()
            End If
            If cell1Value.Trim() = cell2Value.Trim() Then
                result.Remove(0, result.length)
                result.Append(cell1Value.Trim())
                result.AppendLine()
                Return result.toString()
            End If
        Next nextIndex
    Next index
    Return result.toString()
End Function

'获取表单摘要数据
Public Function GetFormSummary() As String
    Dim control As Control
    '    Dim control As Control = Me.FindControl("XTextBox1")
    '    If control IsNot Nothing Then
    '       Return control.Text
    '    End If
    Dim str_Return As String = ""

    '意识
    If Me.FindControl("XComboBox1") IsNot Nothing And Me.FindControl("XComboBox1").Text <> "" Then
        str_Return = "意识：" + Me.FindControl("XComboBox1").Text + ";"
    End If

    '	'瞳孔
    '	Control = Me.FindControl("XCheckBox3")
    '	If Ctype(Control,CheckBox).Checked Then
    '		str_Return += "左瞳孔：" + Control.Text + ";"
    '	Else
    '		If Me.FindControl("XComboBox5") IsNot Nothing And Me.FindControl("XComboBox5").Text <> "" Then
    '			str_Return += "左瞳孔：对光反应:" + Me.FindControl("XComboBox5").Text
    '			If Me.FindControl("XTextBox11").Text <> "" Then
    '				str_Return += "," + Me.FindControl("XTextBox11").Text + "mm"
    '			End If
    '			str_Return += ";"
    '		End If
    '	End If

    '	Control = Me.FindControl("XCheckBox4")
    '	If Ctype(Control,CheckBox).Checked Then
    '		str_Return += "右瞳孔：" + Control.Text + ";"
    '	Else
    '		If Me.FindControl("XComboBox8") IsNot Nothing And Me.FindControl("XComboBox8").Text <> "" Then
    '			str_Return += "右瞳孔：对光反应:" + Me.FindControl("XComboBox8").Text
    '			If Me.FindControl("XTextBox12").Text <> "" Then
    '				str_Return += "," + Me.FindControl("XTextBox12").Text + "mm"
    '			End If
    '			str_Return += ";"
    '		End If
    '	End If

    '皮肤
    Dim ll_i As Integer
    Dim re_no As Integer = 0
    For ll_i = 1 To 11
        Control = Me.FindControl("XCheckBox" & ll_i)
        If CType(Control, CheckBox).Checked Then
            If re_no = 0 Then
                str_Return += "皮肤:"
                re_no = 1
                str_Return += Control.Text
            Else
                str_Return += "、" + Control.Text
            End If
        End If
    Next

    If re_no = 1 Then
        str_Return += ";"
    End If


    '体温
    Control = Me.FindControl("XTextBox3")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += Me.FindControl("XComboBox2").Text + ":" + CType(control, TextBox).Text + "℃;"
    End If

    '脉搏
    Control = Me.FindControl("XTextBox4")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += "脉搏:" + CType(control, TextBox).Text + "次/分;"
    End If

    '心率
    Control = Me.FindControl("XTextBox5")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += "心率:" + CType(control, TextBox).Text + "次/分;"
    End If

    '呼吸
    Control = Me.FindControl("XTextBox7")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += "呼吸:" + CType(control, TextBox).Text + "次/分;"
    End If

    '血压
    If Me.FindControl("XTextBox8").Text <> "" And Me.FindControl("XTextBox9").Text <> "" Then
        str_Return += Me.FindControl("XComboBox3").Text + ":" + Me.FindControl("XTextBox8").Text + "/" + Me.FindControl("XTextBox9").Text + ";"
    End If

    '心电监护
    If Me.FindControl("XComboBox6").Text <> "" Then
        str_Return += "心电监护:" + Me.FindControl("XComboBox6").Text + ";"
    End If

    '氧饱和度
    Control = Me.FindControl("XTextBox6")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += "氧饱和度:" + CType(control, TextBox).Text + "%;"
    End If

    '血糖
    Control = Me.FindControl("XTextBox1")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += "血糖:" + CType(control, TextBox).Text + ";"
    End If

    '手术敷料
    Control = Me.FindControl("XTextBox2")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += "手术敷料:" + CType(control, TextBox).Text + ";"
    End If

    '心律
    Control = Me.FindControl("XTextBox10")
    If control IsNot Nothing And CType(control, TextBox).Text <> "" Then
        str_Return += "心律:" + CType(control, TextBox).Text + ";"
    End If

    '    Return String.Empty
    Return str_Return
End Function


'Occurs when the component is clicked.
Private Sub XButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim recorddate As DateTime
    Me.GetSystemContext("评估时间", recorddate)
    Me.SyncPhysicalData(recorddate)
End Sub


'在 ListControl 上更改 SelectedValue 属性的值时引发的事件。
Private Sub XComboBox3_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If Me.XueyaTable Is Nothing Then
        Exit Sub
    End If
    Me.SetControlText("XTextBox8", "")
    Me.SetControlText("XTextBox9", "")

    Dim xcbo As XComboBox = CType(sender, XComboBox)
    If xcbo Is Nothing Then
        Exit Sub
    End If
    Dim xcboText As String = xcbo.Text
    Dim xueya1 As String = String.Empty
    Dim xueya2 As String = String.Empty

    If xcboText = "早血压" Then
        xueya1 = Me.XueyaTable("血压high")
        xueya2 = Me.XueyaTable("血压Low")
    ElseIf xcboText = "晚血压" Then
        xueya1 = Me.XueyaTable("血压high2")
        xueya2 = Me.XueyaTable("血压Low2")
    ElseIf xcboText = "血压3" Then
        xueya1 = Me.XueyaTable("血压high3")
        xueya2 = Me.XueyaTable("血压Low3")
    ElseIf xcboText = "血压4" Then
        xueya1 = Me.XueyaTable("血压high4")
        xueya2 = Me.XueyaTable("血压Low4")
    ElseIf xcboText = "血压5" Then
        xueya1 = Me.XueyaTable("血压high5")
        xueya2 = Me.XueyaTable("血压Low5")
    ElseIf xcboText = "血压6" Then
        xueya1 = Me.XueyaTable("血压high6")
        xueya2 = Me.XueyaTable("血压Low6")
    End If

    If Not String.IsNullOrEmpty(xueya1) OrElse Not String.IsNullOrEmpty(xueya2) Then
        Me.SetControlText("XTextBox8", xueya1)
        Me.SetControlText("XTextBox9", xueya2)
    End If
End Sub

